function formatDateTimeYMDHMS(inputTime) {    
    var date = new Date(inputTime);  
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = date.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    var h = date.getHours();  
    h = h < 10 ? ('0' + h) : h;  
    var minute = date.getMinutes();  
    var second = date.getSeconds();  
    minute = minute < 10 ? ('0' + minute) : minute;    
    second = second < 10 ? ('0' + second) : second;   
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;    
};

function formatDateTimeYMDHMSDAY(inputTime) {    
    var date = new Date(inputTime);  
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = date.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    var h = date.getHours();  
    h = h < 10 ? ('0' + h) : h;  
    var minute = date.getMinutes();  
    var second = date.getSeconds();  
    minute = minute < 10 ? ('0' + minute) : minute;    
    second = second < 10 ? ('0' + second) : second;   
    return y + '年' + m + '月' + d+'日 '+h+':'+minute+':'+second;    
};

function formatDateTimeYMDHM(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    return y + '-' + m + '-' + d+' '+h+':'+minute+':00';
};
function formatDateTimeYMDH(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    return y + '-' + m + '-' + d+' '+h+':00';
};

function formatDateTimeYMD(inputTime) {    
    var date = new Date(inputTime);  
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = date.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    
    return y + '-' + m + '-' + d;    
}; 

function convertDateFromString(dateString) { 
	if (dateString) { 
		var arr1 = dateString.split(" "); 
		var sdate = arr1[0].split('-'); 
		var date = new Date(sdate[0], sdate[1]-1, sdate[2]); 
		return date;
	} 
}
// 计算两个时间相差天数
function dateDiff(date1, date2){     
	var type1 = typeof date1, type2 = typeof date2;     
	if(type1 == 'string')     
		date1 = stringToTime(date1);     
	else if(date1.getTime)     
		date1 = date1.getTime();     
	if(type2 == 'string')     
		date2 = stringToTime(date2);     
	else if(date2.getTime)     
		date2 = date2.getTime(); 
	return parseInt((date2 - date1) / 1000 / 60 / 60 / 24)+1;//除1000是毫秒，不加是秒 
} 

function isToday(str) {
    if (new Date(str).toDateString() === new Date().toDateString()) {
        //今天
        return true;
    } else if (new Date(str) < new Date()){
        //之前
        return false;
    }
}
//字符串转成Time(dateDiff)所需方法 
function stringToTime(string){     
	var f = string.split(' ', 2);     
	var d = (f[0] ? f[0] : '').split('-', 3);     
	var t = (f[1] ? f[1] : '').split(':', 3);     
	return (new Date(     
	parseInt(d[0], 10) || null,     
	(parseInt(d[1], 10) || 1)-1,     
	parseInt(d[2], 10) || null,     
	parseInt(t[0], 10) || null,    
	parseInt(t[1], 10) || null,     
	parseInt(t[2], 10) || null)).getTime(); 
}

function getDate(AddDayCount,date) {
    var dd =date;
    dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1;//获取当前月份的日期
    var d = dd.getDate();
    return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
}
//比较时间大小
function CompareDate(d1,d2)
{
  return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}
// 开始时间不能大于结束时间
function startTimeChange(){
	 var startTime=$('#start_time').val();
	 var endTime=$('#end_time').val();
	 if(CompareDate(startTime,endTime)){
		 $('#end_time').val(startTime);
	  }
}

function endTimeChange(){
	 var startTime=$('#start_time').val();
	 var endTime=$('#end_time').val();
	 if(CompareDate(startTime,endTime)){
		 $('#start_time').val(endTime);
	 }
}